<template>
    <div class="body_background" :style="GetWindowBackground">
        <div class="body_background padding-top10">
            <div class="block-box items-start">
                <div class="big-font-size three-color">供应商信息</div>
                <ul class="create-box">
                    <li>
                        <div class="big-font-size second-color">供应商名称</div>
                        <input type="text" class=""/>
                    </li>
                    <li>
                        <div class="big-font-size second-color">联系人姓名</div>
                        <input type="text" class=""/>
                    </li>
                    <li>
                        <div class="big-font-size second-color">联系人电话</div>
                        <input type="text" class=""/>
                    </li>
                    <li>
                        <div class="big-font-size second-color">所在地区</div>
                        <input type="text"
                               class="disabledInput"
                               placeholder="省/市/区"
                               @click="addressShowFun"
                               v-model="addressText"
                        />
                    </li>
                    <li>
                        <div class="big-font-size second-color">详细地址</div>
                        <input type="text" class=""/>
                    </li>
                    <li>
                        <div class="big-font-size second-color">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注</div>
                        <input type="text" class=""/>
                    </li>
                </ul>
            </div>
            <div class="button-box">
                <mt-button class="width120 middle-font-size" @click="cancelFun">取消</mt-button>
                <mt-button class="width120 middle-font-size background white-color" @click="goSupplierListFun">提交
                </mt-button>
            </div>
        </div>

        <!--地址选择器-->
        <mt-popup
                v-model="addressShow"
                position="bottom"
                class="address-box"
        >
            <div class="address-top-box">
                <div>已选</div>
                <div @click="addressShowFun">确定</div>
            </div>
            <mt-picker :slots="slots" value-key="name" @change="onValuesChange"></mt-picker>
        </mt-popup>
    </div>



</template>

<script>
    import {Picker} from 'mint-ui';

    export default {
        name: "SupplierCreate",
        data() {
            return {
                GetWindowBackground: {
                    'min-height': ''
                },
                myaddress:this.$store.state.addressData,
                addressShow:false,//地址弹框是否显示
                addressText:'',//地址名称
                slots: [
                    {
                        flex: 1,
                        values: this.$store.state.addressData,
                        defaultIndex: 10,
                        className: 'slot1',
                        textAlign: 'center'
                    }, {
                        divider: true,
                        content: '-',
                        className: 'slot2'
                    }, {
                        flex: 1,
                        values: this.$store.state.addressData[0].children,
                        defaultIndex: 0,
                        className: 'slot3',
                        textAlign: 'center'
                    }, {
                        divider: true,
                        content: '-',
                        className: 'slot4'
                    }, {
                        flex: 1,
                        values: this.$store.state.addressData[0].children[0].children,
                        defaultIndex: 0,
                        className: 'slot5',
                        textAlign: 'center'
                    }
                ]
            }
        },
        mounted() {
            console.log(this.myaddress[0])
        },
        methods: {
            onValuesChange (picker, values) {
                var myaddress=this.myaddress[0]
                if (!values[0]) {
                    this.$nextTick(() => {
                        if (this.myAdress) {
                            // 赋默认值
                        } else {
                           picker.setValues([myaddress, myaddress.children[0], myaddress.children[0].children[0]])
                        }
                    })
                } else {
                    picker.setSlotValues(1, values[0].children)
                    let town = []
                    if (values[1]) {
                        town = values[1].children
                    }
                    picker.setSlotValues(2, town)
                }
            },
            //显示地址
            addressShowFun(){
                this.addressShow=!this.addressShow
            },
            //跳转供应商列表
            goSupplierListFun() {
                this.$router.push('/SupplierList')
            },
            cancelFun() {
                this.$router.push('/SupplierList')
            },
            getHeight() {
                // 获取浏览器高度，减去顶部搜索栏和导航栏的值 55 + 50（可动态获取）,再减去底部高度值60
                this.GetWindowBackground['min-height'] = window.innerHeight + 'px'
            },
        }
        ,
        // 生命周期 - 创建完成（可以访问当前this实例）
        created() {
            window.addEventListener('resize', this.getHeight) // 注册监听器
            this.getHeight() // 页面创建时先调用一次
        }
        ,
        // 生命周期 - 销毁完成
        destroyed() {
            window.removeEventListener('resize', this.getHeight)
        }
        ,
    }
</script>

<style lang="scss" scoped>

    .padding-top10 {
        padding-top: 15px;
    }

    .block-box {
        width: calc(100% - 80px);
        padding: 25px;
    }

    .create-box {
        width: 100%;
        padding-bottom: 20px;
        margin-top: 5px;
        li {
            width: 100%;
            height: 45px;
            display: flex;
            align-items: flex-end;
            justify-content: space-between;
            div {
                margin-bottom: 7px;
            }
            input {
                width: calc(100% - 100px);
                height: 30px;
                border-top: 0;
                border-left: 0;
                border-right: 0;
                border-bottom: 1px solid #ebedf1;
                outline: none;
                list-style: none;
            }
        }
    }

    .button-box {
        width: 100%;
        display: flex;
        justify-content: space-around;
        align-items: center;
        position: fixed;
        bottom: 45px;
        .width120 {
            width: 120px;
            border: 1px solid #05c569;
            color: #05c569;
            border-radius: 10px;
        }
    }
    .disabledInput{
        letter-spacing: 5px;
    }
    .address-box{
        width: calc(100% - 40px);
        height: 300px;
        padding: 0 20px;
        .address-top-box {
            line-height: 40px;
            display: flex;
            justify-content: space-between;
            letter-spacing: 1px;
            font-size: 15px;
        }
    }
</style>